package com.party.poster.draw;

import com.party.poster.element.Canvas;

import java.awt.*;
import java.awt.image.BufferedImage;

public class CanvasDraw {

    public static BufferedImage draw(Canvas canvas){
        BufferedImage background = canvas.getImage();
        if (background == null){
            background = new BufferedImage(canvas.getSize().getWidth(), canvas.getSize().getHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = background.createGraphics();
            graphics.fillRect(0,0,canvas.getSize().getWidth(),canvas.getSize().getHeight());
            graphics.setColor(canvas.getColor());
            graphics.setBackground(canvas.getColor());
            graphics.dispose();
        }
        return background;
    }
}
